package com.itheima.sfbx.insurance.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.insurance.dto.CoefficentVO;
import com.itheima.sfbx.insurance.service.ICoefficentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api
@RestController
@RequestMapping("coefficent")
public class CoefficentController {

    @Autowired
    ICoefficentService coefficentService;


    /**
     * 分页查询系数项
     *
     * @param coefficentVO 查询条件
     * @param pageNum      页码
     * @param pageSize     每页条数
     * @return Page<CoefficentVO>
     */
    @PostMapping("page/{pageNum}/{pageSize}")
    @ApiOperation(value = "系数项分页", notes = "系数项分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coefficentVO", value = "系数项VO对象", required = true, dataType = "CoefficentVO"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", value = "页码", example = "1", dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "pageSize", value = "每页条数", example = "10", dataType = "Integer")
    })
    @ApiOperationSupport(includeParameters = {"coefficentVO.coefficentKey", "coefficentVO.coefficentKeyName", "coefficentVO.coefficentVal", "coefficentVO.sortNo", "coefficentVO.remake"})
    public ResponseResult<Page<CoefficentVO>> findCoefficentVOPage(
            @RequestBody CoefficentVO coefficentVO,
            @PathVariable("pageNum") int pageNum,
            @PathVariable("pageSize") int pageSize) {
        Page<CoefficentVO> coefficentVOPage = coefficentService.findPage(coefficentVO, pageNum, pageSize);
        return ResponseResultBuild.successBuild(coefficentVOPage);

    }



    /**
     * 保存系数项
     *
     * @param coefficentVO
     * @return CoefficentVO
     * @Description 保存系数项
     */
    @PutMapping
    @ApiOperation(value = "保存Coefficent", notes = "添加Coefficent")
    @ApiImplicitParam(name = "coefficentVO", value = "系数项VO对象", required = true, dataType = "CoefficentVO")
    @ApiOperationSupport(
            includeParameters = {"coefficentVO.coefficentKey", "coefficentVO.coefficentKeyName", "coefficentVO.coefficentVal", "coefficentVO.sortNo", "coefficentVO.remake"})
    public ResponseResult<CoefficentVO> createCategory(@RequestBody CoefficentVO coefficentVO) {
        CoefficentVO categoryVOResult = coefficentService.save(coefficentVO);
        return ResponseResultBuild.successBuild(categoryVOResult);
    }

    /**
     * 更新系数项
     * @param coefficentVO
     * @return  Boolean
     */
    @PatchMapping
    @ApiOperation(value = "更新Coefficent", notes = "更新Coefficent")
    @ApiImplicitParam(name = "coefficentVO", value = "系数项VO对象", required = true, dataType = "CoefficentVO")
    @ApiOperationSupport(includeParameters = {"coefficentVO.coefficentId", "coefficentVO.coefficentKey", "coefficentVO.coefficentKeyName", "coefficentVO.coefficentVal", "coefficentVO.sortNo", "coefficentVO.remake"})
    public ResponseResult<Boolean> updateCategory(@RequestBody CoefficentVO coefficentVO) {
        Boolean flag = coefficentService.update(coefficentVO);
        return ResponseResultBuild.successBuild(flag);
    }

    /**
     * 删除系数项
     * @param coefficentVO
     * @return  Boolean
     */
    @DeleteMapping
    @ApiOperation(value = "删除Coefficent", notes = "删除Coefficent")
    @ApiImplicitParam(name = "coefficentVO", value = "系数项VO对象", required = true, dataType = "CoefficentVO")
    @ApiOperationSupport(includeParameters = {"coefficentVO.checkedIds"})
    public ResponseResult<Boolean> deleteCategory(@RequestBody CoefficentVO coefficentVO) {
        Boolean flag = coefficentService.delete(coefficentVO.getCheckedIds());
        return ResponseResultBuild.successBuild(flag);
    }

    /***
     * @description 多条件查询系数项列表
     * @param coefficentVO 系数项VO对象
     * @return List<CoefficentVO>
     */
    @PostMapping("list")
    @ApiOperation(value = "多条件查询系数项列表",notes = "多条件查询系数项列表")
    @ApiImplicitParam(name = "coefficentVO",value = "系数项VO对象",required = true,dataType = "CoefficentVO")
    @ApiOperationSupport(includeParameters = {"coefficentVO.dataState","coefficentVO.coefficentKey","coefficentVO.coefficentKeyName","coefficentVO.coefficentVal","coefficentVO.sortNo","coefficentVO.remake","coefficentVO.coefficentType"})
    public ResponseResult<List<CoefficentVO>> coefficentList(@RequestBody CoefficentVO coefficentVO) {
        List<CoefficentVO> coefficentVOList = coefficentService.findList(coefficentVO);
        return ResponseResultBuild.successBuild(coefficentVOList);
    }

    /***
     * @description 系数项key查询CoefficentVO
     * @param coefficentKey 系数项key
     * @return CoefficentVO
     */
    @PostMapping("coefficent-key/{coefficentKey}")
    @ApiOperation(value = "系数项key查询CoefficentVO",notes = "系数项key查询CoefficentVO")
    @ApiImplicitParam(paramType = "path",name = "coefficentKey",value = "系数项key",dataType = "String")
    public ResponseResult<CoefficentVO> findByCoefficentKey(@PathVariable("coefficentKey") String coefficentKey) {
        CoefficentVO coefficentVO = coefficentService.findByCoefficentKey(coefficentKey);
        return ResponseResultBuild.successBuild(coefficentVO);
    }
}
